package com.zpark.servlet_session;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 退出登录
 *      清空session数据（session失效）
 */
@WebServlet("/exit.do")
public class ExitServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取session对象
        HttpSession session = req.getSession();
        // 使session失效
        session.invalidate();

        // 转发到登录页面
        RequestDispatcher dispatcher = req.getRequestDispatcher("/login.html");
        dispatcher.forward(req, resp);

    }
}
